
using System;
namespace Velocity4Net.Runtime.Directives
{

    /**
     * This represents scoping and metadata for #foreach,
     * adding index, count, hasNext, isFirst and isLast info.
     *
     * @author Nathan Bubna
     * @version $Id$
     */
    public class ForeachScope : Scope
    {
        internal int index = -1;
        internal bool hasNext = false;

        public ForeachScope(Object owner, Object replaces)
            : base(owner, replaces)
        {
        }

        public int Index
        {
            get
            {
                return index;
            }
        }

        public int Counter
        {
            get
            {
                return index + 1;
            }
        }

        public bool HasNext
        {
            get
            {
                return hasNext;
            }
        }


        public bool IsFirst
        {
            get
            {
                return index < 1;
            }
        }

        public bool IsLast
        {
            get
            {
                return !hasNext;
            }
        }
    }
}